package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.happy.cat.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import com.happy.cat.project.system.domain.UserReport;
import com.happy.cat.project.system.service.IUserReportService;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.common.utils.poi.ExcelUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.happy.cat.framework.web.page.TableDataInfo;

/**
 * 用户举报处理Controller
 *
 * @author verne
 * @date 2020-08-23
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/userReport" )
@Api("用户举报处理 API")
public class UserReportController extends BaseController {

    private final IUserReportService iUserReportService;

    /**
     * 查询用户举报处理列表
     */
    @ApiOperation(value = "查询用户举报处理列表",notes = "查询用户举报处理列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:userReport:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserReport userReport)
    {
        startPage();
        LambdaQueryWrapper<UserReport> lqw = new LambdaQueryWrapper<UserReport>();
        if (StringUtils.isNotBlank(userReport.getCode())){
            lqw.eq(UserReport::getCode ,userReport.getCode());
        }
        if (userReport.getReportType()!= null){
            lqw.eq(UserReport::getReportType ,userReport.getReportType());
        }
        if (userReport.getAccountId() != null){
            lqw.eq(UserReport::getAccountId ,userReport.getAccountId());
        }
        if (userReport.getReportTime() != null){
            lqw.eq(UserReport::getReportTime ,userReport.getReportTime());
        }
        if (userReport.getReportAccountId() != null){
            lqw.eq(UserReport::getReportAccountId ,userReport.getReportAccountId());
        }
        if (StringUtils.isNotBlank(userReport.getReportText())){
            lqw.eq(UserReport::getReportText ,userReport.getReportText());
        }
        if (StringUtils.isNotBlank(userReport.getReportImgs())){
            lqw.eq(UserReport::getReportImgs ,userReport.getReportImgs());
        }
        if (StringUtils.isNotBlank(userReport.getReportReason())){
            lqw.eq(UserReport::getReportReason ,userReport.getReportReason());
        }
        if (StringUtils.isNotBlank(userReport.getReportSource())){
            lqw.eq(UserReport::getReportSource ,userReport.getReportSource());
        }
        if (userReport.getStatus() != null){
            lqw.eq(UserReport::getStatus ,userReport.getStatus());
        }
        if (StringUtils.isNotBlank(userReport.getHandleText())){
            lqw.eq(UserReport::getHandleText ,userReport.getHandleText());
        }
        if (userReport.getHandleStatus() != null){
            lqw.eq(UserReport::getHandleStatus ,userReport.getHandleStatus());
        }
        if (StringUtils.isNotBlank(userReport.getHandleBy())){
            lqw.eq(UserReport::getHandleBy ,userReport.getHandleBy());
        }
        if (userReport.getHandleTime() != null){
            lqw.eq(UserReport::getHandleTime ,userReport.getHandleTime());
        }
        if (userReport.getNotifyType() != null){
            lqw.eq(UserReport::getNotifyType ,userReport.getNotifyType());
        }
        if (userReport.getNotifyUsers() != null){
            lqw.eq(UserReport::getNotifyUsers ,userReport.getNotifyUsers());
        }
        List<UserReport> list = iUserReportService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出用户举报处理列表
     */
    @ApiOperation(value = "导出用户举报处理列表",notes = "导出用户举报处理列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userReport:export')" )
    @Log(title = "用户举报处理" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(UserReport userReport) {
        LambdaQueryWrapper<UserReport> lqw = new LambdaQueryWrapper<UserReport>(userReport);
        List<UserReport> list = iUserReportService.list(lqw);
        ExcelUtil<UserReport> util = new ExcelUtil<UserReport>(UserReport. class);
        return util.exportExcel(list, "userReport" );
    }

    /**
     * 获取用户举报处理详细信息
     */
    @ApiOperation(value = "获取用户举报处理详细信息",notes = "获取用户举报处理详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userReport:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iUserReportService.getById(id));
    }

    /**
     * 新增用户举报处理
     */
    @ApiOperation(value = "新增用户举报处理",notes = "新增用户举报处理",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userReport:add')" )
    @Log(title = "用户举报处理" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserReport userReport) {
        return toAjax(iUserReportService.save(userReport) ? 1 : 0);
    }

    /**
     * 修改用户举报处理
     */
    @ApiOperation(value = "修改用户举报处理",notes = "修改用户举报处理",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userReport:edit')" )
    @Log(title = "用户举报处理" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserReport userReport) {
        return toAjax(iUserReportService.updateById(userReport) ? 1 : 0);
    }

    /**
     * 删除用户举报处理
     */
    @ApiOperation(value = "删除用户举报处理",notes = "删除用户举报处理",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userReport:remove')" )
    @Log(title = "用户举报处理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iUserReportService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
